home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / video / tseng.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.8 KB  |  158 lines

  1. /*
  2.  * Copyright (C) 1990-1992 by Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  * tseng.c    - support routines for Tseng Labs ET3000 and ET4000 chipsets
  16.  */
  17.  
  18. #include    "vdev.h"
  19. #include    "svga.h"
  20.  
  21. #define    ET3000        0x01        /* ET3000 chipset    */
  22. #define    ET4000        0x02        /* ET4000 chipset    */
  23.  
  24. #define    M_256K        0x10
  25. #define    M_512K        0x20
  26. #define    M_1024K        0x40
  27.  
  28. #define    GRAPHICS    (SVGA_MODE_SUPPORTED | SVGA_GRAPHICS_MODE)
  29. #define    TEXT        (SVGA_MODE_SUPPORTED | SVGA_TEXT_MODE)
  30.  
  31. static struct svga_mode_info tseng_modes[] =
  32. {
  33.     {    1024,    768,    8,    0x38,    GRAPHICS },
  34.     {    800,    600,    8,    0x30,    GRAPHICS },
  35.     {    640,    480,    8,    0x2e,    GRAPHICS },
  36.     {    320,    200,    8,    0x13,    GRAPHICS },
  37.     {    80,    25,    0,    0x03,    TEXT     },
  38.     {    0,    0,    0,    0x00,    0        }
  39. };
  40.  
  41. static void    tseng3_bank_switch();
  42. static void    tseng4_bank_switch();
  43. static int    tseng_present();
  44.  
  45. /*ARGSUSED*/
  46. int
  47. tseng_init(
  48.     char    *name,
  49.     struct vdev    *v
  50.     )
  51. {
  52.     int        r;
  53.     void    (*tseng_bank_switch)();
  54.  
  55.     if (! (r = tseng_present()))
  56.     return -1;
  57.  
  58.  
  59.     if (r == ET4000)
  60.     {
  61.     v->v_name = "Tseng Labs ET4000 chipset";
  62.     tseng_bank_switch = tseng4_bank_switch;
  63.     }
  64.     else
  65.     {
  66.     v->v_name = "Tseng Labs ET3000 chipset";
  67.     tseng_bank_switch = tseng3_bank_switch;
  68.     tseng_modes[0].attributes &= ~SVGA_MODE_SUPPORTED;
  69.     }
  70.  
  71.     svga_setup(v, tseng_modes, tseng_bank_switch);
  72.  
  73.     return 0;
  74. }
  75.  
  76. int
  77. tseng_probe()
  78. {
  79.     return tseng_present();
  80. }
  81.  
  82. /*
  83.  * tseng_present()    - check for presence or ET3000 or ET4000
  84.  */
  85. static int
  86. tseng_present()
  87. {
  88.     int        base;
  89.     int        old;
  90.     int        new;
  91.  
  92.     outb(0x3bf, 0x03);
  93.     base = (inb(0x3cc) & 0x01) ? 0x3d0 : 0x3b0;
  94.  
  95.     outb(base + 8, 0xa0);
  96.  
  97.     inb(0x3da);
  98.     outb(0x3c0, 0x16);
  99.     old    = inb(0x3c1);
  100.  
  101.     inb(0x3da);
  102.     outb(0x3c0, 0x16);
  103.     outb(0x3c0, old ^ 0x10);
  104.  
  105.     inb(0x3da);
  106.     outb(0x3c0, 0x16);
  107.     new    = inb(0x3c1);
  108.  
  109.     inb(0x3da);
  110.     outb(0x3c0, 0x16);
  111.     outb(0x3c0, old);
  112.  
  113.     if (new != (old ^ 0x10))
  114.     return 0;
  115.  
  116.     outb(base+4, 0x33);
  117.     old    = inb(base+5);
  118.     outb(base+5, old ^ 0x0f);
  119.     new = inb(base+5);
  120.     outb(base+5, old);
  121.  
  122.     if (new == (old ^ 0x0f))
  123.     return ET4000;
  124.     else
  125.     return ET3000;
  126. }
  127.  
  128. /*
  129.  * tseng3_bank_switch()
  130.  */
  131. static void
  132. tseng3_bank_switch(
  133.     int        x
  134.     )
  135. {
  136.     x    &= 7;
  137.     x    |= (x << 3);
  138.  
  139.     outb(0x3cd, x | 0x40);
  140. }
  141.  
  142. /*
  143.  * tseng4_bank_switch()
  144.  */
  145. static void
  146. tseng4_bank_switch(
  147.     int        x
  148.     )
  149. {
  150.     x    &= 0xf;
  151.     x    |= (x << 4);
  152.  
  153.     outb(0x3bf, 0x03);
  154.     outb(0x3d8, 0xa0);
  155.  
  156.     outb(0x3cd, x);
  157. }
  158.